Skip to content

Conversation

@shsms
Copy link
Contributor

@shsms shsms commented Jun 18, 2025

No description provided.

Copilot AI review requested due to automatic review settings June 18, 2025 08:48
@shsms shsms requested a review from a team as a code owner June 18, 2025 08:48
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:experimental Affects the experimental package labels Jun 18, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances GroupingLatestValueCache by fully adopting the Mapping interface, updating the get method’s behavior, and reflecting those changes in tests and release notes.

  • Implement Mapping methods (__getitem__, __iter__, __len__) and overload get
  • Change get to return a default/None instead of raising ValueError, and switch to KeyError in __getitem__
  • Update integration tests and release notes to match the new interface

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/test_grouping_latest_value_cache_integration.py Adapted tests to expect get returning None or provided default instead of raising
src/frequenz/channels/experimental/_grouping_latest_value_cache.py Added Mapping inheritance, mapping methods, overloads, and switched exception types
RELEASE_NOTES.md Noted the addition of Mapping interface in release notes
Comments suppressed due to low confidence (2)

tests/test_grouping_latest_value_cache_integration.py:25

  • Consider adding tests for the new Mapping interface methods (__getitem__, __len__, and iteration) to ensure full coverage of the GroupingLatestValueCache behavior.
    assert cache.get(0) is None

RELEASE_NOTES.md:13

  • Add a note under a ‘Breaking Changes’ section to document that get() no longer raises ValueError (now returns None or a provided default) and that __getitem__ raises KeyError for missing keys.
- This release introduces the experimental `GroupingLatestValueCache`.  It is similar to the `LatestValueCache`, but accepts an additional key-function as an argument, which takes each incoming message and returns a key for that message.  The latest value received for each unique key gets cached and is available to look up on-demand through a `collections.abc.Mapping` interface.

Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it is worth keeping c.has_key(k) instead of requiring the use of k in c.

Also not sure if it might be worth implementing also the methods automatically mixed in by Mapping and its subclasses: __contains__, items, values, __eq__, and __ne__, otherwise they are probably calculated via the iterator or something like that, which could be pretty inefficient.

image
image

Comment on lines 48 to 50
T_co = typing.TypeVar("T_co", covariant=True)
T = typing.TypeVar("T")
HashableT = typing.TypeVar("HashableT", bound=typing.Hashable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: Document these (adding a docstring below them), so they are shown in the docs index.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are internal, not exposed from the _grouping_latest_value_cache module. Not sure if they should be though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess both are fine. If they are not exported, the docs will show it as a "string" without any links, and it will not be present in the ToC. If the types are self explanatory we can keep it as it is. If they are not documented/exported, users will not know about the possible bound= arguments or constraints (or if it is co/contravariant, but for those we usually use the suffixes), so if it is important to the user to know any of that info, that could be a good reason to export and document.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a commit to do this. I'm somewhat doubtful about exposing them from the experimental package directly, but that seems to be the best option available.

@shsms
Copy link
Contributor Author

shsms commented Jun 23, 2025

Not sure if it is worth keeping c.has_key(k) instead of requiring the use of k in c.

Also not sure if it might be worth implementing also the methods automatically mixed in by Mapping and its subclasses: __contains__, items, values, __eq__, and __ne__, otherwise they are probably calculated via the iterator or something like that, which could be pretty inefficient.

All done.

shsms added 2 commits June 23, 2025 11:35
Signed-off-by: Sahas Subramanian <[email protected]>
@shsms shsms requested a review from llucax June 23, 2025 09:37
llucax
llucax previously approved these changes Jun 23, 2025
Making the part of the public API makes it easy for users to look them
up and understand how to use them.

Signed-off-by: Sahas Subramanian <[email protected]>
@shsms shsms added this pull request to the merge queue Jun 25, 2025
Merged via the queue into frequenz-floss:v1.x.x with commit 4096546 Jun 25, 2025
5 checks passed
@shsms shsms deleted the map-group branch June 25, 2025 08:22
@llucax llucax added this to the v1.10.0 milestone Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation part:experimental Affects the experimental package part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants